package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.parameter.ProcessUserWxInfoBean;
import com.shop2cn.iapi.member.service.ProcessUserWxInfoCall;
import com.ymatou.iapi.dguser.parameter.UpdateUserWxinfoBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.sqlwapper.godmember.GodMemberWapper;
import com.ymttest.utils.TestDataManager;
/**
*接受修改昵称消息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ProcessUserWxInfo{
	private static ProcessUserWxInfoBean processuserwxinfoBean;
	private static ProcessUserWxInfoCall processuserwxinfoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("接受修改昵称消息");
	}

	@Before
	public void caseUp() {
		processuserwxinfoBean=new ProcessUserWxInfoBean();
		processuserwxinfoCall=new ProcessUserWxInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(processuserwxinfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ProcessUserWxInfo_001() {
		Logger.start(true,"接受修改昵称消息成功");
		try {
			Integer shopid = GodmchManageCallService.CreateSellerMch();
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			UpdateUserWxinfoBean updateuserwxinfoBean=new UpdateUserWxinfoBean();
			updateuserwxinfoBean.setUserId(userId);
			updateuserwxinfoBean.setNickname("nick"+TestDataManager.getRandomNum(5));
			DGUserCallService.updateUserWxinfo(updateuserwxinfoBean);
			processuserwxinfoBean.setUserId(userId);
			processuserwxinfoCall.setData(processuserwxinfoBean);
			processuserwxinfoCall.callService();			
			Logger.verifyEquals("ok", processuserwxinfoCall.getReturnData(), "验证返回");
			Logger.verifyEquals(updateuserwxinfoBean.getNickname(),new GodMemberWapper().selectMemberByMemberid(memid).get(0).getNickName(),"验证nickname");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ProcessUserWxInfo_002() {
		Logger.start(true,"接受修改昵称消息成功-修改多个昵称");
		try {
			//一个dguser在多个shop注册member 会有这个情况
			Integer shopid = GodmchManageCallService.CreateSellerMch();
			
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			Integer shopid2 = GodmchManageCallService.CreateSellerMch();
			
			//创建一个新会员
			CreateMemberBean createMem2 = GodMemberService.initCreateMemberBean(shopid2,userId,usercreateBean.getOpenId());
			String memid2 = GodMemberService.creatememberCall(createMem2);
			
			UpdateUserWxinfoBean updateuserwxinfoBean=new UpdateUserWxinfoBean();
			updateuserwxinfoBean.setUserId(userId);
			updateuserwxinfoBean.setNickname("nick"+TestDataManager.getRandomNum(5));
			DGUserCallService.updateUserWxinfo(updateuserwxinfoBean);
			processuserwxinfoBean.setUserId(userId);
			processuserwxinfoCall.setData(processuserwxinfoBean);
			processuserwxinfoCall.callService();			
			Logger.verifyEquals("ok", processuserwxinfoCall.getReturnData(), "验证返回");
			Logger.verifyEquals(updateuserwxinfoBean.getNickname(),new GodMemberWapper().selectMemberByMemberid(memid).get(0).getNickName(),"验证nickname");
			Logger.verifyEquals(updateuserwxinfoBean.getNickname(),new GodMemberWapper().selectMemberByMemberid(memid2).get(0).getNickName(),"验证nickname");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}